# -*- coding:utf-8 -*-
from typing import Optional, Any

from pydantic import BaseModel


class ResponseResult(BaseModel):
    success: Optional[bool] = True
    data: Any = None
    error_msg: Any = None


def model_to_dict(result):
    dict1 = {}
    for k, v in result.__dict__.items():
        if not k.startswith('_sa_instance_state'):
            dict1[k] = v
    return dict1


def models_to_dict(result: list):
    json_result = []
    for row in result:
        json_result.append(model_to_dict(row))
    return json_result


from boltons.iterutils import remap


def remove_dic_null(dic):
    doc_temp = remap(dic, visit=lambda path, key, value: value is not None and value != "" and value != [])
    return doc_temp
